package com.cze.servlet;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public class LoderServlet extends HttpServlet {

    private static ApplicationContext context = null;

    @Override
    public void init() throws ServletException {
        System.out.println("初始化servlet");
        if (context == null) {
            context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        }
    }

    public static Object getBean(String beanName) {
        Object bean = null;
        bean = context.getBean(beanName);
        return bean;
    }


    @Override
    public void destroy() {
        super.destroy();
    }
}